********The programs to replicate the results in the tables of the paper, "Does democracy cause innovation? An empirical study of the Popper Hypothesis"
use submit_rp_1.dta, clear

***summary statistics
local all_var "lpat_uspt2 lcit_pat2 lorig2 dich_dem polity2 n_pr yr_sch lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	sum `all_var' if year<=2010 /**Table 1 descriptive statistics***/
	tabstat `all_var', s(n mean sd) c(s)
	tabstat `all_var' if year<=2010, statistics (mean) by (dich_dem)
	ttable2 `all_var' if year<=2010, by(dich_dem)     /*** Table 1. mean difference test by dich_dem***/

***regression results
	
***basic results
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	reg lpat_uspt2 l.dich_dem `depd' if year<=2010, robust
	est store ols
	xtreg lpat_uspt2 l.dich_dem i.time if year<=2010, fe robust
	est store res1
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res2
	xtreg lpat_uspt2 l.did i.time if all_dem!=1&year<=2010, fe robust
	est store res3
	xtreg lpat_uspt2 l.did `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res4
	xtreg lpat_uspt2 l.did i.year i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res5
	xtreg lpat_uspt2 l.did `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res6
	outreg2 [ols res1 res2 res3 res4 res5 res6] using table2, word dec(3) replace  /**results in Table 2**/
	
***results using alternative dependent variables
	set more off
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lcit_pat2 l.dich_dem i.time if year<=2010, fe robust
	est store res7
	xtreg lcit_pat2 l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res8
	xtreg lcit_pat2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res9
	xtreg lorig2 l.dich_dem i.time if year<=2010, fe robust
	est store res10
	xtreg lorig2 l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res11
	xtreg lorig2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res12
	outreg2 [res7 res8 res9 res10 res11 res12] using table3, word dec(3) replace  /**results in Table 3**/
	
***results using alternative democracy index
	set more off
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res13
	xtreg lcit_pat2 l.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res14
	xtreg lorig2 l.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res15
	xtreg lpat_uspt2 l.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res16
	xtreg lcit_pat2 l.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res17
	xtreg lorig2 l.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res18
	
	outreg2 [res13 res14 res15 res16 res17 res18] using table4, word dec(3) replace  /**results in Table 4**/
	
***results on long-run effects
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim1
	xtreg lpat_uspt2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim2
	xtreg lcit_pat2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm i.time i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim3
	xtreg lcit_pat2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim4
	xtreg lorig2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm i.time i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim5
	xtreg lorig2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm `depd' i.time i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim6
	outreg2 [tim1 tim2 tim3 tim4 tim5 tim6] using table5_A, dec(3) word replace  /**results in Table 5_A**/
	
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 dem_10m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim1
	xtreg lpat_uspt2 dem_20m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim2
	xtreg lcit_pat2  dem_10m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim3
	xtreg lcit_pat2  dem_20m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim4
	xtreg lorig2 dem_10m `depd' i.time i.iso2_code##c.time  if year<=2010, fe robust
	est store tim5
	xtreg lorig2 dem_20m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim6
	
	outreg2 [tim1 tim2 tim3 tim4 tim5 tim6] using table5_B, dec(3) word replace  /**results in Table 5_B**/
	
    set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 L20.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim1
	xtreg lpat_uspt2 L20.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim2
	xtreg lcit_pat2  L20.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim3
	xtreg lcit_pat2  l20.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim4
	xtreg lorig2 L20.polity2 `depd' i.time i.iso2_code##c.time  if year<=2010, fe robust
	est store tim5
	xtreg lorig2 L20.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim6	
	outreg2 [tim1 tim2 tim3 tim4 tim5 tim6] using table5_C, dec(3) word replace  /**results in Table 5_C**/
	
*** Types of democratizaion and innovation	
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 suc_dem par_dem bl_rv_dem i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec1
	xtreg lpat_uspt2 suc_dem par_dem bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec2
	xtreg lcit_pat2 suc_dem par_dem bl_rv_dem i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec3
	xtreg lcit_pat2 suc_dem par_dem bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec4
	xtreg lorig2 suc_dem par_dem bl_rv_dem i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec5
	xtreg lorig2 suc_dem par_dem bl_rv_dem `depd'  i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec6
	outreg2 [dec1 dec2 dec3 dec4 dec5 dec6] using table6, dec(3) word replace  /**results in Table 6**/

*** Innovation and democracy in Eastern Europe transition countries

	use submit_rp_2.dta, clear
	xtset c_id year	
	xtreg lpat_uspt2 l.dich_dem i.year   if year<=2010, fe robust
	est store tra1
	xtreg lpat_uspt2 l.dich_dem  i.year i.c_id##c.year  if year<=2010, fe robust
	est store tra2
	xtreg lpat_uspt2 l.dich_dem  i.year i.c_id##c.year  if year>=1980&year<=2010, fe robust
	est store tra3
	xtreg lpat_uspt2 L.lpat_uspt2 dich_dem i.year, fe robust									
	xtreg lpat_uspt2 exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra4			
	xtreg lpat_uspt2 dem_1t3 dem_4t6 dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra5			
	xtreg lpat_uspt2 L.dich_dem dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra6
	xtreg lpat_uspt2 l.dich_dem  i.year i.c_id##c.year  if c_id!=3&c_id!=4, fe robust
	est store tra7
	xtreg lpat_uspt2 L.dich_dem dem_7tm i.year i.c_id##c.year if c_id!=3&c_id!=4, fe robust
	est store tra8	
	outreg2 [tra1 tra2 tra3 tra4 tra5 tra6 tra7 tra8] using tra_res, dec(3) word replace /**results in table 7***/
    
****Additional robustness check 

****Table S1-1

use supple_rp_1.dta, clear
xtset iso2_code time
set more off
local depd " yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res_wipo1
	xtreg lpat_gra l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res_wipo2
	xtreg lpat_gra l.dich_dem `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res_wipo3
	
set more off
local depd " yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_app l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res_wipo4
	xtreg lpat_app l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res_wipo5
	xtreg lpat_app l.dich_dem `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res_wipo6 	
outreg2 [res_wipo*] using tableS1_1, dec(3) word replace  /***result in Table S1-1***/

***Table S1-2
set more off
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra l.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res13
	xtreg lpat_app l.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res14
	xtreg lpat_gra l.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res15
	xtreg lpat_app l.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res16
outreg2 [res13 res14 res15 res16 ] using tableS1_2, word dec(3) replace /***results in Table S1-2***/

***Table S1-3 
set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim1
	xtreg lpat_app exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim2
	
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra dem_10m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim3
	xtreg lpat_gra dem_20m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim4
	xtreg lpat_app  dem_10m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim5
	xtreg lpat_app  dem_20m `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim6
	
    set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra L20.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim7
	xtreg lpat_gra L20.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim8
	xtreg lpat_app  L20.polity2 `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim9
	xtreg lpat_app  l20.n_pr `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store tim10
outreg2 [tim1 tim3 tim4 tim7 tim8 tim2 tim5 tim6 tim9 tim10] using tableS1_3, dec(3) word replace /***results in table S1-3***/

	
****Table S1-4
	set more off
	xtset iso2_code time
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra suc_dem par_dem bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec1
	xtreg lpat_app suc_dem par_dem bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec2

	set more off
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra suc_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec3
	xtreg lpat_app suc_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec4
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_gra par_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec5
	xtreg lpat_app par_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec6
	xtreg lpat_gra bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec7
	xtreg lpat_app bl_rv_dem `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store dec8
outreg2 [dec1 dec2 dec3 dec4 dec5 dec6 dec7 dec8] using tableS1_4, dec(3) word replace  /***results in Table S1-4 ***/

****Table S1-5 see the end	

****Table S1-6
xtset iso2_code time
set more off
local depd " yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg ljur_art l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res_art1
	xtreg ljur_art l.did `depd' i.time if year<=2010, fe robust
	est store res_art2
	xtreg ljur_art l.did `depd' i.time i.iso2_code##c.time if year<=2010, fe robust
	est store res_art3
	xtreg ljur_art l.did `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res_art4
	xtreg ljur_art l.did `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res_art5
outreg2 [res_art1 res_art2 res_art3 res_art4 res_art5] using tableS1-6, dec(3) word replace /***results in Table S1-6***/
			
****Table S2
set more off
	xtset iso2_code time
	local depd "yr_sch_sec lpop lpop_dnst sp_urb_totl_in_zs open"
	reg lpat_uspt2 l.dich_dem if year<=2010, robust
	est store ols1
	reg lpat_uspt2 l.dich_dem `depd' if year<=2010, robust
	est store ols2
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res2
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res4
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res6
	local depd "rd_GDP yr_sch_sec lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res7
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res8
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res9
	set more off
	local depd "lrd_pc yr_sch_sec lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010, fe robust
	est store res10
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if all_dem!=1&year<=2010, fe robust
	est store res11
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if all_dem!=1&year<=2010, fe robust
	est store res12
outreg2 [ res2 res4 res6 res7 res8 res9 res10 res11 res12] using tableS2, word dec(3) replace  /**results in table S2**/
	
****Table S3
set more off
local depd " yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010&oecd==0, fe robust
	est store no_oecd1
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010&oecd==0, fe robust
	est store no_oecd2		
set more off
local depd " yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010&oecd==1, fe robust
	est store oecd1
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010&oecd==1, fe robust
	est store oecd2	
outreg2 [oecd* no_oecd*] using tableS3_1, dec(3) word replace /***results in table S3-1***/

****Table S3-2	
set more off
	local depd "yr_sch_sec lgdppc lpop lpop_dnst sp_urb_totl_in_zs open"
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010&m_lpat_uspt2>3.25, robust fe
	est store top30
	xtreg lpat_uspt2 l.dich_dem `depd' i.time if year<=2010&m_lpat_uspt2>1.59, robust fe
	est store top50
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010&m_lpat_uspt2>3.25, robust fe
	est store top30_t
	xtreg lpat_uspt2 l.dich_dem `depd' i.time i.iso2_code##c.time if year<=2010&m_lpat_uspt2>1.59, robust fe
	est store top50_t
outreg2 [ top30 top30_t top50 top50_t] using table_a4, word dec(3) replace

****Table S1-5
use supple_rp_2.dta, clear
set more off
xtset c_id year
	xtreg lpat_gra l.dich_dem i.year if year<=2010, fe robust
	est store tra1
	xtreg lpat_gra l.dich_dem  i.year i.c_id##c.year  if year<=2010, fe robust
	est store tra2
	xtreg lpat_gra l.dich_dem  i.year i.c_id##c.year  if year>=1980&year<=2010, fe robust
	est store tra3									
	xtreg lpat_gra exp_5t3 exp_2t0 dem_1t3 dem_4t6 dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra4			
	xtreg lpat_gra dem_1t3 dem_4t6 dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra5			
	xtreg lpat_gra L.dich_dem dem_7tm i.year i.c_id##c.year if year<=2010, fe robust
	est store tra6		
outreg2 [tra1 tra2 tra3 tra4 tra5 tra6] using tableS1_5, dec(3) word replace  /***results in table S1-5**/	
	